﻿@{
    ViewBag.Title = "Album";
    Layout = "~/Views/Shared/_ViewFormPage.cshtml";
}
@section head{
    <script src="/Scripts/AjaxFileUploaderV2.1/ajaxfileupload.js"></script>
    <script type="text/javascript">
        
        $(function() {
            $("#btnSave").on("click", save);


            $("#btnUpload").click(function (e) {
                e.preventDefault();
                ajaxFileUpload();
            });

        });

        function ajaxFileUpload() {
            var dialog = $.ligerDialog.waitting('正在上传,请稍候...');
            $.ajaxFileUpload({
                url: '/File/Upload',
                secureuri: false,
                fileElementId: 'imgFile',
                dataType: 'json',
                cache: false,
                data: { dir: 'image', localUrl: '' },
                success: function (data, status) {
                    if (typeof (data.error) !== 'undefined') {
                        if (data.error === 0) {
                            $("#productImage").attr("src", data.url);
                            $("#ImgUrl").val(data.url);
                        } else {
                            $.ligerDialog.error('上传出错:' + data.message);
                        }
                    }
                },
                error: function (data, status, e) {
                    $.ligerDialog.error('上传出错:' + e);
                }
                ,
                complete: function (XMLHttpRequest, textStatus) {
                    dialog.close();
                }
            })
            return false;
        }


        function save() {
            if ($("form").valid()) {
                $('form').ajaxSubmit({
                    type: "Post",
                    beforeSubmit: function () {
                        $("#btnSave").off("click", save);
                    },
                    success: function (callback) {
                        if (callback) {
                            $.ligerDialog.success('保存成功', function (yes) {
                                self.location.href = "/Company/Photos?aid=" + $("#AlbumId").val();
                            });
                        }
                        else {
                            $("#btnSave").on("click", save);
                            $.ligerDialog.error('保存失败');
                            
                        }
                    },
                    error: function (ex) {
                        $("#btnSave").on("click", save);
                        $.ligerDialog.error('保存失败');
                    }
                });
            }
        }
    </script>
}
@model PhotoVM
<div id="header" class="header">
    <h4>图片管理</h4>
</div>
@using (Html.BeginForm("Photo", "Company", FormMethod.Post))
{
    @Html.HiddenFor(model => model.AlbumId)
    @Html.HiddenFor(model => model.PhotoId)
    <div id="detail_forms">
        <div class="formsItems clearfix">
            <div class="formItem labelItem">
                名称
            </div>
            <div class="formItem textItem">
                @Html.TextBoxFor(model => model.PhotoTitle, new { @class = "texts" })
            </div>
            <div class="formItem msgItem">
            </div>
        </div>
        
         <div class="formsItems clearfix">
            <div class="formItem labelItem">
                图片
            </div>
            <div class="formItem textItem">
                <table border="0">
                    <tr>
                        <td style="height:40px;">
                            <input type="file" id="imgFile" name="imgFile" />
                            <span class="buttons">
                                <a href="javascript:void(0);" id="btnUpload">上传</a>
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div id="showImage">
                                <img src='@Model.PhotoUrl'  style="height:120px; cursor:pointer; width:200px;" alt="点击上传" title="点击上传" id="productImage" />
                            </div>
                        </td>
                        <td style="vertical-align: bottom;">
                            <div style="width: 220px; margin-left: 10px; display: block">
                                <input type="file" id="fileUploader" style="display: none;" name="file_upload" />
                                @Html.HiddenFor(m => m.PhotoUrl)
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="formItem msgItem">
            </div>
        </div>

        <div id="btnContainer" class="formsItems">
            <div class="formItem labelItem">
                &nbsp;
            </div>
            <div class="formItem textItem">
                <a href="javascript:void(0);" id="btnSave">保存</a>
                <a href="/Company/Albums" id="btnCancel">取消</a>
            </div>
            <div class="formItem">
            </div>
        </div>
        <div class="formsItems"></div>
    </div>
}


